﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web.Routing;

namespace RenRen.Web.Mvc {
  public static class HtmlExtensions {
      public static string RenRenInviteLink(this HtmlHelper helper, string name, string text, object  requests, object attributes) {
          TagBuilder builder = new TagBuilder("a");
          builder.MergeAttributes(new RouteValueDictionary( attributes));
          builder.MergeAttribute("name", name);
          builder.InnerHtml = text;
          builder.Attributes["href"] = "javascript:;";
          var reqs =new RouteValueDictionary (requests);
          builder.Attributes["onclick"] = "window.top.parent.location.href='";
          builder.Attributes["onclick"] += "http://apps.renren.com/request.do";
          foreach (var k in reqs) {
              builder.Attributes["onclick"] += builder.Attributes["onclick"].IndexOf("?") > 0 ? "&" : "?";
              builder.Attributes["onclick"] += k.Key + "=" + helper.Encode(k.Value);
          }
          builder.Attributes["onclick"] += "';";
          return builder.ToString(TagRenderMode.Normal);
      }
    }
}
